package lily.ui.bookshelf;

import lily.phs.urh.R;

import android.content.Context;
import android.graphics.drawable.Drawable;
import android.view.Gravity;
import android.widget.LinearLayout;

/**
 * 书架每一层的布局类
 * @author heckassitant
 *
 */
public class CaseLevelView extends LinearLayout {
	
	private static final String TAG = "case";
	private static final int WIDTHRATIO = 1;//控件宽=屏幕宽（横竖屏相同）
	private static final float HEIGHTRATIO = 0.2f;//控件高=屏幕高*ratio（竖屏）
	public int LevelWidth;
	public int LevelHeight;

	public CaseLevelView(Context context) {
		super(context);

		this.setOrientation(LinearLayout.HORIZONTAL);
		this.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.WRAP_CONTENT));
//		this.setGravity(Gravity.CENTER);
		
		//计算控件尺寸
		WindowSizeUtil util = new WindowSizeUtil(getContext());
		LevelWidth = util.ScreenWidth * WIDTHRATIO;
		int h = (util.ScreenWidth>util.ScreenHeight)?util.ScreenWidth:util.ScreenHeight;
		LevelHeight = Math.round(h * HEIGHTRATIO);
		
		Drawable db = getResources().getDrawable(R.drawable.case_middle);
        this.setBackgroundDrawable(db);
        
        this.setGravity(Gravity.BOTTOM);
		this.setPadding(5, 15, 5, 5);
		this.setFocusable(false);
		this.setClickable(false);

       // Log.i(TAG, "level.width="+LevelWidth+",level.height="+LevelHeight);
	}
	
	@Override
	protected void onLayout(boolean changed, int l, int t, int r, int b) {
		// TODO Auto-generated method stub
//		Log.i(TAG, "level.onLayout");
		super.onLayout(changed, l, t, r, b);
	}

	@Override
	protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
		// TODO Auto-generated method stub
//		Log.i(TAG, "level.onMeasure");
		super.onMeasure(widthMeasureSpec, heightMeasureSpec);
	}
}


